@include('public.head')
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="">
        <div>
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>
                        引导城市编辑
                    </h5>
                </div>
                <div class="ibox-content">
                    <form method="post" action="" class="form-horizontal m-t">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">引导城市</label>

                            <div class="col-sm-10">
                                <select class="form-control m-b" name="map_guide">
                                @forelse ($map_lists as $probability)
                                    <option value="{{$probability->id}}" @if ($probability->id == $map_detail->map_guide)selected="selected" @endif>{{$probability->city}}</option>
                                @empty
                                @endforelse
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">图标大小</label>
                            <div class="col-sm-6">
                                <input type="text"  name="value" class="form-control file" style="padding:4px 12px" value="{{$map_detail->value}}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">地址信息</label>
                            <div class="col-sm-6">
                                <script id="article" name="map_value" type="text/plain" style="height:300px;">{!!$map_detail->map_value!!}</script>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <input type="hidden" name="city_id" value="{{$city_id}}">
                        <input type="hidden" name="id" value="{{$id}}">
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                               <button class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var article = UE.getEditor('article');

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $(".m-t").submit(function(e){
        var form = new FormData();

        var city_id = $("input[name='city_id']").val();
        var map_guide = $("select[name='map_guide'] option:selected").val();
        var id = $("input[name='id']").val();
        var value = $("input[name='value']").val();
        var map_value = article.getContent();
        
        
        if(map_guide == ''){
            layer.msg('请选择引导城市!');
            return false;
        }

        form.append("map_id", city_id);
        form.append("map_guide", map_guide);
        form.append("map_value", map_value);
        form.append("id", id);
        form.append("value", value);

        $.ajax({
            url:"/world_city_guide_add_do",    //请求的url地址
            dataType:"json",   //返回格式为json
            data:form,    //参数值
            processData: false,
            contentType: false,   
            type:"POST",   //请求方式
            success:function(req){
                //请求成功时处理
                if(req.status == 0){
                    layer.msg(req.message);
                    return false;
                }
                   
                layer.msg('操作成功！');
                setTimeout(function(){
                     window.location.href = "/world_city_guide/{{$city_id}}";
                },1000); 
            }
        });
        return false;
    });
</script>
</body>
</html>